﻿using System.Data;
using Stiline.Interfaces;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.Linq;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace AdoDAL.Repositories
{
    public abstract class BaseRepository
    {

       private const string ConnectionStringKey = "StilineConnectionString";


        internal SqlConnection CreateConnection()
        {
            return new SqlConnection(ConfigurationManager.ConnectionStrings[ConnectionStringKey].ConnectionString);
        }

        internal SqlCommand CreateStoredProcedureExecutionCommand(string commandText, SqlConnection connection, params SqlParameter[] parameters)
        {
            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }
            var command = new SqlCommand(commandText, connection);
            command.Parameters.AddRange(parameters);
            command.CommandType = CommandType.StoredProcedure;
            return command;
        }
    }
}
